package observerPattern.observerCPattern;


import java.util.ArrayList;
import java.util.List;

/**
 * @program: course
 * @author: lsn
 * @create: 2024-04-28 10:39
 * @description: 角色：具体主题
 */
public class WeChatOfficialAccount implements Subject {
    //储存订阅公众号的微信用户
    private List<Observer> weChatUserList = new ArrayList<Observer>();

    @Override
    public void attach(Observer observer) {
        weChatUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weChatUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weChatUserList) {
            observer.update(message);
        }
    }
}

